﻿using DevExpress.XtraGrid.Demos.util;
using DiaoPaiDaYin;
using DXApplicationTangche.UC.ImpUC;
using DXApplicationTangche.UC.下单MTO.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.下单MTO
{
    public partial class FormMTO团体套号下单 : DevExpress.XtraEditors.XtraForm
    {
        private XtraUserControl团体套号订单一览 xtraUserControl团体套号订单一览 = new XtraUserControl团体套号订单一览();
        private List<SalOrderQueryHeadDTO> salOrderQueryHeadDTOs = new List<SalOrderQueryHeadDTO>();
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }

        public FormMTO团体套号下单()
        {
            InitializeComponent();
            this.xtraUserControl团体套号订单一览 = new XtraUserControl团体套号订单一览();
            this.xtraUserControl团体套号订单一览.Dock = DockStyle.Fill;
            this.panel团体套号订单一览.Controls.Clear();
            this.panel团体套号订单一览.Controls.Add(this.xtraUserControl团体套号订单一览);
        }

        private void dockPanel1_Click_1(object sender, EventArgs e)
        {
            //this.xtraUserControl团体套号订单一览.refreshData();
        }

        private void dateTimePicker结束时间_ValueChanged(object sender, EventArgs e)
        {
            this.StartTime = Convert.ToDateTime(this.dateTimePicker开始时间.Text);
            this.EndTime = Convert.ToDateTime(this.dateTimePicker结束时间.Text);
            this.compareDate(StartTime, EndTime);
        }
        
        private void dateTimePicker开始时间_ValueChanged(object sender, EventArgs e)
        {
            this.StartTime = Convert.ToDateTime(this.dateTimePicker开始时间.Text);
            this.EndTime = Convert.ToDateTime(this.dateTimePicker结束时间.Text);
            this.compareDate(StartTime, EndTime);
        }

        /// <summary>
        /// 比较开始时间结束时间
        /// </summary>
        /// <param name="StartTime"></param>
        /// <param name="EndTime"></param>
        private void compareDate(DateTime StartTime, DateTime EndTime)
        {
            this.StartTime = StartTime;
            this.EndTime = EndTime;
            if (DateTime.Compare(StartTime, EndTime) > 0)
            {
                MessageBox.Show("开始时间不能小于结束时间！");
            }
            else
            {
                this.salOrderQueryHeadDTOs = MTO下单Service.getSaleOerQueryDTOList(this.dateTimePicker开始时间.Value.ToString("yyyy-MM-dd"), this.dateTimePicker结束时间.Value.ToString("yyyy-MM-dd"));
                this.gridControl销售渠道订单数量.DataSource = this.salOrderQueryHeadDTOs;
            }
        }

        private void gridView销售渠道订单数量_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            List<String> details = this.salOrderQueryHeadDTOs[this.gridView销售渠道订单数量.FocusedRowHandle].detailIds;
            //List<String> details = FunctionHelper.GetgridViewValueObject(this.gridView销售渠道订单数量, this.gridView销售渠道订单数量.FocusedRowHandle, "detailIds");
            this.xtraUserControl团体套号订单一览.refreshData(details);
        }

        private void 客户套号扫描成衣条码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List<String> details = this.salOrderQueryHeadDTOs[this.gridView销售渠道订单数量.FocusedRowHandle].detailIds;
            new FormMTO客户套号分录(details).ShowDialog();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {

        }

        private void simpleButton刷新_Click(object sender, EventArgs e)
        {
            this.StartTime = Convert.ToDateTime(this.dateTimePicker开始时间.Text);
            this.EndTime = Convert.ToDateTime(this.dateTimePicker结束时间.Text);
            this.compareDate(StartTime, EndTime);
        }
    }
}
